import axios from "axios";
import NproGress from "nprogress"

export default {
  namespaced: true,
  mutations: {
    INIT_LIST(state, { data, flag }) {
      state.list = data;
      state.loading = false;
    },
    // 添加 解构赋值的引用  不借用vuex的方法需要用 commit 
    // this.$store.commit
    LIST_ADD_ITEM(state,{ item }) {
      state.list.push(item)
    }
  },
  actions: {
    init({ commit }) {
      axios.get("/getList").then((res) => {
        console.log(res.data);
        commit("INIT_LIST", {
          data: res.data,
          flag: false,
        });
        NproGress.done()
      });
    },
  },
  state: {
    list: [],
    loading: true,
  },
};
